package com.yzz.composeweatherproject.activity.viewpager2

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment
import com.yzz.composeweatherproject.R

/**
 * @Author : yangzuozhe
 * @Time : On 2022/6/3 0:37
 *
 * @Description : ViewPagerFragment
 */
class ViewPagerFragment : Fragment() {

    companion object {
        fun newInstance(content: String?): ViewPagerFragment {
            val args = Bundle()
            args.putString("content", content)
            val fragment = ViewPagerFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        return LayoutInflater.from(context).inflate(R.layout.fragment_view_pager, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        view.findViewById<ComposeView>(R.id.mFragmentComposeView)?.setContent {
            arguments?.let { bundle ->
                val content = bundle.getString("content")
                LazyColumn(Modifier.fillMaxSize()) {
                    items(100) {
                        Text(text = "${content.toString()},page=$it")
                    }
                }
            }
        }
    }
}